home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-2.iso / Files II / QuickTime / QT Tools / QuickTime Interfacing.sit / QuickTime Interfacing / SeeMovieRun folder / sources / CQTApp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-19  |  5.9 KB  |  289 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * CQTApp.c
  3.  *
  4.  *    Application methods for a QuickTime demo application.
  5.  *
  6.  *  Copyright © 1992 Joe Zobkiw.  All rights reserved.
  7.  *  Portions Copyright © 1990 Symantec Corporation.  All rights reserved.
  8.  *
  9.  *****/
  10.  
  11. #include "CQTApp.h"
  12. #include "CQTDoc.h"
  13. #include "Commands.h"
  14. #include "Defines.h"
  15. #include "CEBSwitchboard.h"
  16. #include "CEBCollaborator.h"
  17. #include "QuickTime Utilities.h"
  18. #include <TBUtilities.h>
  19. #include <TCLUtilities.h>
  20. #include <Global.h>
  21. #include <GestaltEqu.h>
  22. #include <Movies.h>
  23.  
  24. extern    OSType            gSignature;
  25. extern  long            gQuickTimeVersion;
  26. extern  CEBCollaborator    *gEBCollaborator;
  27.  
  28. #define        kExtraMasters        4
  29. #define        kRainyDayFund        20480
  30. #define        kCriticalBalance    20480
  31. #define        kToolboxBalance        20480
  32.  
  33. /***
  34.  * IQTApp
  35.  *
  36.  *    Initialize the application. Your initialization method should
  37.  *    at least call the inherited method. If your application class
  38.  *    defines its own instance variables or global variables, this
  39.  *    is a good place to initialize them.
  40.  *
  41.  ***/
  42.  
  43. void CQTApp::IQTApp(void)
  44.  
  45. {
  46.     OSErr    err = noErr;
  47.     
  48.     CApplication::IApplication( kExtraMasters, kRainyDayFund, 
  49.                         kCriticalBalance, kToolboxBalance);
  50.     
  51.     if (QuickTimeIsInstalled(&gQuickTimeVersion) == true) {
  52.         FailOSErr(EnterMovies());
  53.     } else {
  54.         gQuickTimeVersion = 0;
  55.         FailOSErr(gestaltUndefSelectorErr);
  56.     }
  57.     
  58.     gEBCollaborator = new(CEBCollaborator);
  59.     gEBCollaborator->IEBCollaborator();
  60. }
  61.  
  62.  
  63. /******************************************************************************
  64.  MakeSwitchboard
  65.  
  66.      Create application's switchboard. We use a special "Event Broadcasting"
  67.      Switchboard that will use our gEBCollaborator instance to broadcast events
  68.      to any available Movie Controllers before handling them itself. 
  69.      
  70.      This is how Movie Controllers get thier events.
  71.      
  72. ******************************************************************************/
  73.  
  74. void CQTApp::MakeSwitchboard( void)
  75. {
  76.     itsSwitchboard = new(CEBSwitchboard);
  77.     ((CEBSwitchboard*)itsSwitchboard)->IEBSwitchboard();
  78. }
  79.  
  80. /***
  81.  * SetUpFileParameters
  82.  *
  83.  *    In this routine, you specify the kinds of files your
  84.  *    application opens.
  85.  *
  86.  *
  87.  ***/
  88.  
  89. void CQTApp::SetUpFileParameters(void)
  90.  
  91. {
  92.     inherited::SetUpFileParameters();    /* Be sure to call the default method */
  93.  
  94.         /**
  95.          **    sfNumTypes is the number of file types
  96.          **    your application knows about.
  97.          **    sfFileTypes[] is an array of file types.
  98.          **    You can define up to 4 file types in
  99.          **    sfFileTypes[].
  100.          **
  101.          **/
  102.  
  103.     sfNumTypes = 1;
  104.     sfFileTypes[0] = kApplicationFileType;    // in CQTDoc.h
  105.  
  106.         /**
  107.          **    Although it's not an instance variable,
  108.          **    this method is a good place to set the
  109.          **    gSignature global variable. Set this global
  110.          **    to your application's signature. You'll use it
  111.          **    to create a file (see CFile::CreateNew()).
  112.          **
  113.          **/
  114.  
  115.     gSignature = kApplicationSignature;        // in CQTApp.h
  116. }
  117.  
  118.  
  119. /***
  120.  * SetUpMenus 
  121.  *
  122.  * Set up menus which must be created at run time, such as a
  123.  * Font menu. You can eliminate this method if your application
  124.  * does not have any such menus.
  125.  *
  126. ***/
  127.  
  128.  void CQTApp::SetUpMenus()
  129.  {
  130.  
  131.   inherited::SetUpMenus();  /*  Superclass takes care of adding     
  132.                                 menus specified in a MBAR id = 1    
  133.                                 resource    
  134.                             */                          
  135.  
  136.         /* Add your code for creating run-time menus here */    
  137.  }
  138.  
  139.  
  140.  
  141. /***
  142.  * DoCommand
  143.  *
  144.  *    Your application will probably handle its own commands.
  145.  *    Remember, the command numbers from 1-1023 are reserved.
  146.  *  The file Commands.h contains all the predefined TCL
  147.  *  commands.
  148.  *
  149.  *    Be sure to call the default method, so you can get
  150.  *    the default behvior for standard commands.
  151.  *
  152.  ***/
  153. void CQTApp::DoCommand(long theCommand)
  154.  
  155. {
  156.     switch (theCommand) {
  157.     
  158.         /* Your commands go here */
  159.         case cmdAbout:
  160.             Alert(kAboutALRT, nil);
  161.             break;
  162.         
  163.         //
  164.         // show standard movie preview open dialog. if the user selects a movie,
  165.         // then we pass the FSSpec to OpenQTDocument which will handle opening
  166.         // one of this application’s documents.
  167.         //
  168.         
  169.         case cmdOpen: {
  170.             FSSpec    spec;
  171.             if (GetMovieFileFSSpec(&spec)) {
  172.                 OpenQTDocument(&spec);
  173.             }
  174.         }
  175.         break;
  176.             
  177.         default:    inherited::DoCommand(theCommand);
  178.                     break;
  179.     }
  180. }
  181.  
  182.  
  183. /***
  184.  *
  185.  * UpdateMenus 
  186.  *
  187.  *   Perform menu management tasks
  188.  *
  189. ***/
  190.  
  191.  void CQTApp::UpdateMenus()
  192.  {
  193.   inherited::UpdateMenus();     /* Enable standard commands */      
  194.  
  195.     /* Enable the commands handled by your Application class */ 
  196.  }
  197.  
  198.  
  199. /***
  200.  * Exit
  201.  *
  202.  *    Chances are you won't need this method.
  203.  *    This is the last chance your application gets to clean up
  204.  *  things like temporary files before terminating.
  205.  *
  206.  ***/
  207.  
  208. void CQTApp::Exit()
  209.  
  210. {
  211.     if (gQuickTimeVersion != 0)
  212.         ExitMovies();                    // tell QuickTime we are through
  213.     
  214.     if (gEBCollaborator != NULL)
  215.         gEBCollaborator->Dispose();        // nuke our global CEBCollaborator
  216. }
  217.  
  218.  
  219. /***
  220.  * CreateDocument
  221.  *
  222.  *    The user chose New from the File menu.
  223.  *    In this method, you need to create a document and send it
  224.  *    a NewFile() message.
  225.  *
  226.  ***/
  227.  
  228. void CQTApp::CreateDocument()
  229.  
  230. {
  231.     CQTDoc    *theDocument = NULL;
  232.     
  233.     TRY
  234.     {
  235.         theDocument = new(CQTDoc);
  236.         theDocument->IQTDoc(this, TRUE);
  237.         theDocument->NewFile();
  238.     }
  239.     
  240.     CATCH
  241.     {
  242.         //if (theDocument) theDocument->Dispose();
  243.         ForgetObject(theDocument);
  244.     }
  245.     ENDTRY;
  246. }
  247.  
  248. /***
  249.  * OpenDocument
  250.  *
  251.  * Converts the TCL’s SFReply into an FSSpec and then calls OpenQTDocument to
  252.  * open the movie document. This is only used when a movie is double-clicked
  253.  * from the Finder or an odoc AppleEvent is sent.
  254.  * 
  255.  ***/
  256.  
  257. void CQTApp::OpenDocument(SFReply *macReply)
  258. {
  259.     FSSpec    spec;
  260.     
  261.     FailOSErr(FSMakeFSSpec(macReply->vRefNum, 0L, macReply->fName, &spec));
  262.     this->OpenQTDocument(&spec);
  263. }
  264.  
  265. /***
  266.  * OpenQTDocument
  267.  *
  268.  * Open a document using the FSSpec provided. In this case, it will be spec to a
  269.  * Movie document.
  270.  * 
  271.  ***/
  272.  
  273. void CQTApp::OpenQTDocument(FSSpec *spec)
  274. {
  275.     CQTDoc    *theDocument = NULL;
  276.  
  277.     TRY
  278.     {    
  279.         theDocument = new(CQTDoc);
  280.         theDocument->IQTDoc(this, TRUE);
  281.         theDocument->OpenQTFile(spec);
  282.     }
  283.     CATCH
  284.     {
  285.         ForgetObject(theDocument);
  286.     }
  287.     ENDTRY;
  288. }
  289.